import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

public class Test {
    int[] nums;
    String jewels = "aA";
    String stones = "aAAbbbb";
    
    class Node {
        int val;
        Node next;
        Node random;
        
        public Node(int val) {
            this.val = val;
            this.next = null;
            this.random = null;
        }
    }
    
    public int singleNumber(int[] nums) {
        HashSet<Integer> set = new HashSet<>();
        for (int i = 0; i < nums.length; i++) {
            if (!set.contains(nums[i])) {
                set.add(nums[i]);
            }else {
                set.remove(nums[i]);
            }
        }
        for (int i = 0; i < nums.length; i++) {
            if (set.contains(nums[i])) {
                return nums[i];
            }
        }
        
        return -1;
    }
    
    
    public int numJewelsInStones(String jewels, String stones) {
        int count = 0;
        HashSet<Character> set = new HashSet<>();
        char[] arrayOfJewels = jewels.toCharArray();
        char[] arrayOfStones = stones.toCharArray();
        for (int i = 0; i < arrayOfJewels.length; i++) {
            set.add(arrayOfJewels[i]);
        }
        for (int i = 0; i < arrayOfStones.length; i++) {
            if (set.contains(arrayOfStones[i])) {
                count++;
            }
        }
        return count;
    }
    
    public Node copyRandomList(Node head) {
        Map<Node,Node> map = new HashMap<>();
        Node cur = head;
        while (cur != null) {
            Node newNode = new Node(cur.val);
            map.put(cur,newNode);
            cur = cur.next;
        }
        cur = head;
        while (cur != null) {
            map.get(cur).next = map.get(cur.next);
            map.get(cur).random = map.get(cur.random);
            cur = cur.next;
        }
        
        return map.get(head);
    }
    
}
